package com.andox.fn.inf.rpc.rest.parser;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

import com.andox.fn.inf.rpc.rest.proxy.ServiceBean;


/**   
 * @ClassName:   ServiceDefinitionParser   
 * @Description: TODO  
 * @author:      Andox
 * @date:        2019年7月29日 下午12:06:18   
 *     
 */
public class ServiceDefinitionParser extends AbstractContractDefinitionParser {
    private static final String REF     = "ref";

    @Override
    protected void doParseInternal(Element element, ParserContext parserContext,
                                   BeanDefinitionBuilder builder) {
    	
        String ref = element.getAttribute(REF);
        if (!StringUtils.hasText(ref))
        	throw new IllegalStateException("ref attribute is emtpy");
        
        builder.addPropertyReference(REF, ref);
        MethodDefinitionParser.parse(element, parserContext, builder);
    }

    @Override
    protected Class<?> getBeanClass(Element element) {
        return ServiceBean.class;
    }

    @Override
    public String supportTagName() {
        return RestRpcNamespaceHandler.SERVICE_TAG;
    }
}